package com.like.network;

import com.like.utils.Constants;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtil {

    static Retrofit mRetrofit = null;
    static Retrofit mNoAesRetrofit = null;

    public static Retrofit getRetrofit() {
        if (mRetrofit == null) {
            OkHttpClient client = new OkHttpClient.Builder().addInterceptor(
                    new AESInterceptor())
//                    .addNetworkInterceptor(new TokenInterceptor())
                    .build();
            mRetrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL)
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create()).build();
        }
        return mRetrofit;
    }

    public static Retrofit getNoAesRetrofit() {
        if (mNoAesRetrofit == null)
            mNoAesRetrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL).build();
        return mNoAesRetrofit;
    }

    @SuppressWarnings("unchecked")
    public static <T> T getService(@SuppressWarnings("rawtypes") Class clazz) {
        return (T) getRetrofit().create(clazz);
    }

    @SuppressWarnings("unchecked")
    public static <T> T getNoAesService(Class clazz) {
        return (T) getNoAesRetrofit().create(clazz);
    }

}
